package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

/**
 * 阿里云呼叫中心通话结果
 *
 * @author 吴洪波
 * @version v1.0
 * @date 21/06/29 14:29
 * @since v1.0
 */
@Getter
public enum AliyunCallCenterResultEnum {

    /**
     * 未接通
     */
    NO_ANSWER(0, "enum.aliyunCallCenterResult.name.noAnswer", "noAnswer"),

    /**
     * 正常
     */
    SUCCESS(1, "enum.aliyunCallCenterResult.name.success", "success"),

    /**
     * IVR中放弃
     */
    ABANDONED_IN_CONTACT_FLOW(2, "enum.aliyunCallCenterResult.name.abandonedInContactFlow", "abandonedInContactFlow"),

    /**
     * 排队放弃
     */
    ABANDONED_IN_QUEUE(3, "enum.aliyunCallCenterResult.name.abandonedInQueue", "abandonedInQueue"),

    /**
     * 振铃放弃
     */
    ABANDONED_IN_RING(4, "enum.aliyunCallCenterResult.name.AbandonedInRing", "AbandonedInRing"),

    /**
     * 客户拒接
     */
    REJECT(5, "enum.aliyunCallCenterResult.name.reject", "reject"),
    ;

    /**
     * 枚举值 --
     */
    private final int code;

    /**
     * 枚举信息--中文名称
     */
    private final String name;

    /**
     * 枚举描述 --英文名称
     */
    private final String alias;

    AliyunCallCenterResultEnum(int code, String name, String alias) {
        this.code = code;
        this.name = name;
        this.alias = alias;
    }

    /**
     * 根据名字获取编码
     *
     * @param name 名字
     * @return 编码
     */
    public static Integer getCodeByName(String name) {
        AliyunCallCenterResultEnum[] values = AliyunCallCenterResultEnum.values();
        for (AliyunCallCenterResultEnum value : values) {
            if (value.alias.equalsIgnoreCase(name)) {
                return value.code;
            }
        }
        return -1;
    }

    /**
     * 根据编码获取名字
     *
     * @param code 编码
     * @return code
     */
    public static String getNameByCode(Integer code) {
        AliyunCallCenterResultEnum[] values = AliyunCallCenterResultEnum.values();
        for (AliyunCallCenterResultEnum value : values) {
            if (value.code == code) {
                return value.getName();
            }
        }
        return "";
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
